Skip to content

Fix: Resolve Thymeleaf 3.1.4+ TemplateProcessingException in variables.css (Issue #5251)#5264

Closed
EIHEI2 wants to merge 1 commit intocodecentric:masterfrom
EIHEI2:fix-issue-47
Closed

Fix: Resolve Thymeleaf 3.1.4+ TemplateProcessingException in variables.css (Issue #5251)#5264
EIHEI2 wants to merge 1 commit intocodecentric:masterfrom
EIHEI2:fix-issue-47

Conversation

@EIHEI2
Copy link
Copy Markdown

@EIHEI2 EIHEI2 commented Apr 15, 2026

Description

This PR fixes the TemplateProcessingException that occurs with Thymeleaf 3.1.4.RELEASE when processing the variables.css template.

Problem

Thymeleaf 3.1.4+ introduced stricter security restrictions that forbid bean references (@cssColorUtils) in CSS templates, causing the following error:

Solution

  1. Added a model attribute to that pre-computes RGB values from the theme palette
  2. Updated template to use the pre-computed map instead of calling directly
  3. Added bean configuration for better compatibility

Changes

  • : Added dependency and model attribute method
  • : Updated template expressions to use instead of bean method calls
  • : Added bean configuration

Testing

The fix avoids bean references in the template while maintaining the same functionality. The RGB values are computed once per request in the controller instead of per-variable in the template.

Fixes #5251

…estriction

- Add cssColors model attribute to UiController with pre-computed RGB values
- Update variables.css template to use cssColors instead of @cssColorUtils bean reference
- Add SpringStandardDialect bean configuration for compatibility

This fixes the TemplateProcessingException caused by Thymeleaf 3.1.4.RELEASE
which forbids bean references (@cssColorUtils) in CSS templates.
@EIHEI2 EIHEI2 requested a review from a team as a code owner April 15, 2026 02:04
@ModelAttribute(value = "cssColors", binding = false)
public Map<String, String> getCssColors() {
var palette = uiSettings.getTheme().getPalette();
return Map.of(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the values here come from the configuration, I would personally just compute this map once in the constructor when the controller is created and just reuse that value every time the endpoint gets called.

That's just a small optimisation :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the properties may be changed at runtime (via Spring Boot Admin's Properties UI + Spring Cloud mechanisms), i tend to have it in a method instead of a constructor.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. I was not aware of this possibility.
Makes sense then.

public UiController(String publicUrl, UiExtensions uiExtensions, Settings uiSettings) {
private final CssColorUtils cssColorUtils;

public UiController(String publicUrl, UiExtensions uiExtensions, Settings uiSettings, CssColorUtils cssColorUtils) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have extended/changed the controller constructor, check all parts where this is used. I guess that at least the tests are broken.

Copy link
Copy Markdown
Contributor

@cdprete cdprete Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EIHEI2

Error: Failed to execute goal io.spring.javaformat:spring-javaformat-maven-plugin:0.0.47:validate (default) on project spring-boot-admin-server-ui: Formatting violations found in the following files:
Error: * /home/runner/work/spring-boot-admin/spring-boot-admin/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/UiController.java

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to build this PR locally ... compile error:

./mvnw clean install -DskipTests -Dspring-javaformat.skip=true

INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/Dev/git/privat/spring-boot-admin/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java:[135,24] constructor UiController in class de.codecentric.boot.admin.server.ui.web.UiController cannot be applied to given types;
  required: java.lang.String,de.codecentric.boot.admin.server.ui.extensions.UiExtensions,de.codecentric.boot.admin.server.ui.web.UiController.Settings,de.codecentric.boot.admin.server.ui.config.CssColorUtils
  found:    java.lang.String,de.codecentric.boot.admin.server.ui.extensions.UiExtensions,de.codecentric.boot.admin.server.ui.web.UiController.Settings
  reason: actual and formal argument lists differ in length
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Spring Boot Admin 4.1.0-SNAPSHOT:
[INFO]
[INFO] Spring Boot Admin .................................. SUCCESS [  4.128 s]
[INFO] Spring Boot Admin Dependencies ..................... SUCCESS [  0.292 s]
[INFO] Spring Boot Admin Build ............................ SUCCESS [  0.453 s]
[INFO] Spring Boot Admin Server ........................... SUCCESS [01:18 min]
[INFO] Spring Boot Admin Server UI ........................ FAILURE [02:41 min]
[INFO] Spring Boot Admin Client ........................... SKIPPED
[INFO] Spring Boot Admin Docs ............................. SKIPPED
[INFO] Spring Boot Admin Server Cloud ..................... SKIPPED
[INFO] Spring Boot Admin Server Starter ................... SKIPPED
[INFO] Spring Boot Admin Client Starter ................... SKIPPED
[INFO] Spring Boot Admin Samples .......................... SKIPPED
[INFO] Spring Boot Admin Server custom UI ................. SKIPPED
[INFO] Spring Boot Admin Sample Servlet ................... SKIPPED
[INFO] Spring Boot Admin Sample Reactive .................. SKIPPED
[INFO] Spring Boot Admin Sample War ....................... SKIPPED
[INFO] Spring Boot Admin Sample Hazelcast ................. SKIPPED
[INFO] Spring Boot Admin Sample Eureka .................... SKIPPED
[INFO] Spring Boot Admin Sample Consul .................... SKIPPED
[INFO] Spring Boot Admin Sample Zookeeper ................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:05 min
[INFO] Finished at: 2026-04-20T11:08:36+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) on project spring-boot-admin-server-ui: Compilation failure
[ERROR] /D:/Dev/git/privat/spring-boot-admin/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java:[135,24] constructor UiController in class de.codecentric.boot.admin.server.ui.web.UiController cannot be applied to given types;
[ERROR]   required: java.lang.String,de.codecentric.boot.admin.server.ui.extensions.UiExtensions,de.codecentric.boot.admin.server.ui.web.UiController.Settings,de.codecentric.boot.admin.server.ui.config.CssColorUtils
[ERROR]   found:    java.lang.String,de.codecentric.boot.admin.server.ui.extensions.UiExtensions,de.codecentric.boot.admin.server.ui.web.UiController.Settings
[ERROR]   reason: actual and formal argument lists differ in length
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :spring-boot-admin-server-ui

AD001+hoehmann@dinmPF5F7PQ0 • 2026-04-20 • 11:08 • MINGW64 /d/Dev/git/privat/spring-boot-admin (fix-issue-47) •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed the expectations from @SteKoe were correct then.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahoehma the bean is already registered in the context.
Therefore, for the sake of testing, you can just add it as parameter in https://github.com/codecentric/spring-boot-admin/blob/master/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java#L100 and then pass that parameter to https://github.com/codecentric/spring-boot-admin/blob/master/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java#L127.

Moreover, I would suggest you to run it with -Dmaven.test.skip=true instead of -DskipTests so that Maven doesn't even try to compile the tests (which maybe would fail as well).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the few compile errors by myself ... now I try to include the 4.1.0-SNAPSHOT into my project ... keep you informed asap :-)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm ... I'm using the snapshot now ... build is fine ... startup also fine .. but then when I try to open sba ...

2026-04-20 12:42:12 [          http-nio-9090-exec-9] ERROR - [] - org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]:170 - Servlet.service() for servlet [dispatcherServlet] threw exception
org.thymeleaf.exceptions.ConfigurationException: Conflicting execution attribute. Two or more dialects specify an execution attribute with the same name "StandardExpressionParser".
	at org.thymeleaf.DialectSetConfiguration.build(DialectSetConfiguration.java:268)
	at org.thymeleaf.EngineConfiguration.<init>(EngineConfiguration.java:123)
	at org.thymeleaf.TemplateEngine.initialize(TemplateEngine.java:341)
	at org.thymeleaf.TemplateEngine.getConfiguration(TemplateEngine.java:411)
	at org.thymeleaf.spring6.view.ThymeleafView.renderFragment(ThymeleafView.java:265)
	at org.thymeleaf.spring6.view.ThymeleafView.render(ThymeleafView.java:193)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1305)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1042)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:866)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1000)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:892)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:622)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:874)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:128)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:107)

Copy link
Copy Markdown
Contributor

@cdprete cdprete Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please try removing the spring standard dialect bean which was added in the PR?
I suspect there is already one coming from Spring Boot itself, therefore now Thymeleaf doesn't know which one to use.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Now its up and running - CSS issues gone! 👍

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdprete
Copy link
Copy Markdown
Contributor

cdprete commented Apr 17, 2026

@EIHEI2 please fix as well your commit message since it's referencing another PR (i.e.: #47) instead of your issue.

@cdprete
Copy link
Copy Markdown
Contributor

cdprete commented Apr 20, 2026

@SteKoe given we're getting no fixes here, I've collected and applied all the findings (plus more) in #5285 instead.
/cc @ahoehma maybe you can test that one shortly too. Just to be doubly sure ;)

@ahoehma
Copy link
Copy Markdown

ahoehma commented Apr 20, 2026

@SteKoe given we're getting no fixes here, I've collected and applied all the findings (plus more) in #5285 instead. /cc @ahoehma maybe you can test that one shortly too. Just to be doubly sure ;)

Branch: fix/5251

[INFO] --- checkstyle:3.6.0:check (checkstyle-validation) @ spring-boot-admin-server-ui ---
[INFO] Beginne Prüfung...
[ERROR] D:\Dev\git\privat\spring-boot-admin\spring-boot-admin-server-ui\src\test\java\de\codecentric\boot\admin\server\ui\web\UiControllerTest.java:28:1: Wrong order for 'de.codecentric.boot.admin.server.ui.config.AdminServerUiProperties' import. [SpringImportOrder]
Prüfung beendet.
[INFO] There is 1 error reported by Checkstyle 12.3.1 with src/checkstyle/checkstyle.xml ruleset.
[ERROR] src\test\java\de\codecentric\boot\admin\server\ui\web\UiControllerTest.java:[28,1] (extension) SpringImportOrder: Wrong order for 'de.codecentric.boot.admin.server.ui.config.AdminServerUiProperties' import.

./mvnw clean install -DskipTests -Dspring-javaformat.skip=true -Dcheckstyle.skip=true

Green ... and inside my app the CSS still fixed 👍

@cdprete
Copy link
Copy Markdown
Contributor

cdprete commented Apr 20, 2026

@SteKoe given we're getting no fixes here, I've collected and applied all the findings (plus more) in #5285 instead. /cc @ahoehma maybe you can test that one shortly too. Just to be doubly sure ;)

Branch: fix/5251

[INFO] --- checkstyle:3.6.0:check (checkstyle-validation) @ spring-boot-admin-server-ui ---
[INFO] Beginne Prüfung...
[ERROR] D:\Dev\git\privat\spring-boot-admin\spring-boot-admin-server-ui\src\test\java\de\codecentric\boot\admin\server\ui\web\UiControllerTest.java:28:1: Wrong order for 'de.codecentric.boot.admin.server.ui.config.AdminServerUiProperties' import. [SpringImportOrder]
Prüfung beendet.
[INFO] There is 1 error reported by Checkstyle 12.3.1 with src/checkstyle/checkstyle.xml ruleset.
[ERROR] src\test\java\de\codecentric\boot\admin\server\ui\web\UiControllerTest.java:[28,1] (extension) SpringImportOrder: Wrong order for 'de.codecentric.boot.admin.server.ui.config.AdminServerUiProperties' import.

./mvnw clean install -DskipTests -Dspring-javaformat.skip=true -Dcheckstyle.skip=true

Green ... and inside my app the CSS still fixed 👍

Thanks for checking it, @ahoehma.
I've fixed the checkstyle violation(s) in the meantime and the build passes.
So, now it's up to @SteKoe and the team to decide how to proceed.

@SteKoe
Copy link
Copy Markdown
Contributor

SteKoe commented Apr 20, 2026

Hey there, thanks for your hard work! That's much appreciated! I will close this PR as it is superseeded by the new PR created by you, @cdprete.

@SteKoe SteKoe closed this Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

org.thymeleaf.exceptions.TemplateProcessingException in variables.css

4 participants